package yi;

import java.io.File;

public class NumberOne {
    public static void main(String[] args) {
        File file=new File("G:/file");
        long fileSize = getFileSize(file);
        System.out.println(fileSize);
    }

    public static long getFileSize(File dir){
        //TODO 计算文件夹的大小
        if (dir.exists()){
            if (dir.isDirectory()){
                File[] files = dir.listFiles();
                long size=0;
                for (File file : files) {
                    size+=getFileSize(file);
                }
                return size;
            }else {
                return dir.length();
            }
        }else {
            return -1;
        }
    }
}
